﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace HCFramework.Control.HtmlControlStaticVer
{
    public partial class Edit : System.Web.UI.Page
    {
        public string FileName
        {
            get
            {
                return Request.QueryString["fileName"] + "";
            }
        }

        private string filePath
        {
            get
            {
                string filePath = Server.MapPath("~/Control/HtmlControlStaticVer/File/") + FileName + "." + C.LanguageController.GetLanguageCurrent() + ".html";
                if(!File.Exists(filePath)) M.FileM.Write(filePath, "");
                return filePath;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (FileName == "")
            {
                M.Message.ShowError("QueryString fileName không tồn tại!");
                return;
            }
            if (!IsPostBack)
            {
                LoadContent();
            }
        }

        private void LoadContent()
        {
            string content = File.ReadAllText(filePath);
            RadEditor1.Content = content;
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            File.WriteAllText(filePath, RadEditor1.Content);
            M.Common.GoToPreviousPage();
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            M.Common.GoToPreviousPage();
        }
    }
}